

const path = require('path');
const staticImg = path.join(__dirname, 'static');

function SensorbitUnoBlocks(Blockly) {
    var show_color = "#f59057";








    // tm1637数码管初始化
    Blockly.Blocks.microbit_tm1637Init = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/23.4-digit clock 7-segment.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_TM1637)
           .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P8', "pin8"],
            ['P12', "pin12"],
            ['P13', "pin13"],
            ['P15', "pin15"],
           ]),"tm1637CLK")
           .appendField(Blockly.Msg.MICROBIT_DIO)
           .appendField(new Blockly.FieldDropdown([
            ['P1', "pin1"],
            ['P2', "pin2"],
            ['P12', "pin12"],
            ['P14', "pin14"],
            ['P16', "pin16"],
           ]),"tm1637DIO")
           this.appendDummyInput("")
           .appendField(Blockly.Msg.MICROBIT_TM1637INTENSITY)
           .appendField(new Blockly.FieldDropdown([
            ["7", "7"],
            ["0", "0"],
            ["1", "1"],
            ["2", "2"],
            ["3", "3"],
            ["4", "4"],
            ["5", "5"],
            ["6", "6"]
        ]), "tm1637Intensity");
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

     // tm1637数码管展示
     Blockly.Blocks.microbit_tm1637display = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/23.4-digit clock 7-segment.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_TM1637DISPLAY)
            .appendField(new Blockly.FieldDropdown([
             [Blockly.Msg.MICROBIT_TM1637FIRST, "0"],
             [Blockly.Msg.MICROBIT_TM1637SECOND, "1"],
             [Blockly.Msg.MICROBIT_TM1637THIRD, "2"],
             [Blockly.Msg.MICROBIT_TM1637FORTH, "3"],
            ]),"TM1637Bit");
            this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_TM1637DISPLAYDATA)
            this.appendValueInput("tm1637Data", Number)
            this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_TM1637DISPLAYPOINT)
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.MICROBIT_OPEN, "True"],
                [Blockly.Msg.MICROBIT_CLOSE, "False"],
            ]),"tm1637Point")
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

    // tm1637数码管显示数字  
    Blockly.Blocks.microbit_tm1637ShowNumber = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/23.4-digit clock 7-segment.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_TM1637SHOWNUMBER)
            this.appendValueInput("tm1637Number", Number)
            this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_TM1637DISPLAYPOINT)
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.MICROBIT_OPEN, "True"],
                [Blockly.Msg.MICROBIT_CLOSE, "False"],
            ]),"tm1637Point")
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

    // tm1637数码管清屏
    Blockly.Blocks.microbit_tm1637Clear = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/23.4-digit clock 7-segment.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_TM1637CLEAR)
            .appendField(new Blockly.FieldDropdown([
             [Blockly.Msg.MICROBIT_TM1637FIRST, "0"],
             [Blockly.Msg.MICROBIT_TM1637SECOND, "1"],
             [Blockly.Msg.MICROBIT_TM1637THIRD, "2"],
             [Blockly.Msg.MICROBIT_TM1637FORTH, "3"],
             [Blockly.Msg.MICROBIT_TM1637ALL, ""],
            ]),"TM1637Bit1");
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };



    return Blockly;
}

module.exports = SensorbitUnoBlocks;

